package com.atguigu.sms.strategy;

import com.atguigu.servicebase.exceptionhandler.GuliException;
import com.atguigu.sms.model.param.SmsPlaceHolderParameter;
import lombok.extern.slf4j.Slf4j;

import java.util.Set;

/**
 * 短信发送拒绝策略-完全匹配,只有当短信入参与短信模板占位符完全匹配时才允许发送
 *
 */
@Slf4j
public class SmsSendTotallyMatchStrategy implements SmsSendRejectStrategy {
    @Override
    public void reject(SmsTemplateContext context, SmsPlaceHolderParameter parameter) {
        Set<String> parameterSet = getParameterSet(parameter);
        if (!parameterSet.containsAll(context.getPlaceHolderKeySet())) {
            log.error("短信占位符替换参数与短信模板不完全匹配,templateContent = {},parameter = {}", context.getTemplateContent(), parameter);
            throw new GuliException(20001, "短信占位符替换参数与短信模板完全不匹配");
        }

    }
}
